#pragma once

#include "Frame.h"
//#include "../source/Player.h"
//#include "AnimationManager.h"
#include "../SGD Wrappers/SGD_Listener.h"
#include "../SGD Wrappers/SGD_Event.h"
#include "../SGD Wrappers/SGD_EventManager.h"
#include "../SGD Wrappers/SGD_String.h"
//#include "../SGD Wrappers/Entity.h"


#include "../SGD Wrappers/SGD_GraphicsManager.h"

class CPlayer;
class Entity;

class CAnimation 
	//: public SGD::Listener
{
	friend class CAnimationManager;
public: 
	CAnimation();
	~CAnimation();

	/**********************************************************/
	// Initialize & Terminate
	//void	Initialize();
	void	Terminate(void);// for the image handle

	/**********************************************************/
	// Animation Controls:
	void	Update(float elapsedTime);
	void	Render(SGD::Point position, bool flipped,
		float scale, SGD::Color color);

	int GetNumActiveRects();
	SGD::Rectangle GetCurrActiveRect(int num);
	SGD::Rectangle GetCurrPassiveRect();
	

	void	Restart(bool looping, float speed);
	void	Pause(bool pause)	{ m_bPlaying = !pause; }

	bool	IsPlaying(void) const	{ return m_bPlaying; }
	bool	IsFinished(void) const	{ return m_bFinished; }
	void SetFinished(bool finished) { m_bFinished = finished; }
	void SetPlaying(bool playing){ m_bPlaying = playing; }

	void SetOwner(Entity * owner) { m_pOwner = owner; }
	void SetName(std::string s) { m_sName = s; }
	Entity * GetOwner(void) { return m_pOwner; }
	std::string GetName() { return m_sName; }

	void SetCurrFrame(int currFrame) { m_nCurrFrame = currFrame; }
	void SetLooping(bool loop) { m_bLooping = loop; }

	//CAnimation * GetInstance() { return this; }

	//std::vector< CFrame > GetFrames

	void HandleEvent(const SGD::Event* pEvent);

private:
	
	//	Animation variables:
	SGD::HTexture m_hImage = SGD::INVALID_HANDLE;

	Entity * m_pOwner = nullptr;

	std::vector< CFrame > vFrames;// vector of frames
	

	int						m_nCurrFrame = 0;

	float					m_fTimeWaited = 0.0f;
	float					m_fSpeed = 1.0f;		// multiplier: 2.0 - twice as fast

	bool					m_bPlaying = false;
	bool					m_bLooping = false;
	bool					m_bFinished = false;
	std::string				m_sName;
};

